home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: leeds.ac.uk!news
- From: csyamc@scs.leeds.ac.uk (A M Casey)
- Subject: changing strings via pointers
- Message-ID: <1996Feb22.125436.25503@leeds.ac.uk>
- NNTP-Posting-Host: csgi23.leeds.ac.uk
- Organization: The University of Leeds, School of Computer Studies
- Date: Thu, 22 Feb 1996 12:54:35 +0000 (GMT)
-
- I reading in strings from a file using fgets, which stores the "\n" in
- the array of chars which I have declared using a pointer.
-
- The thing is, I want to get rid of the "\n" and replace it with "\0", but
- obviously I can only do this using the pointer. I'm using the following code:
-
- char *Contents < pointer to string
-
- int count = 0;
-
-
- while (*(Contents + count)!= NULL) /* the end of string is not reached */
- {if (*(Contents + count) == atoi("\n"))
- /* change the \n to a \0 and set the next char along to null */
- {
- *(Contents + count) = atoi("\0");
-
- *(Contents + count + 1) = NULL;
-
-
- }
- else
- /* read in the next char */
- {
- count++;
-
- I think the problem maybe my way of using the pointer - I can print out each
- char as I get to it, but it doesnt seem to change the array at all.
- Should I be using atoi?, it doesnt seem to work without it.
-
- Cheers
-
- ANdy
-
-
-
-
-